DataScience Blog

Python- Part 4

August 14, 2020

Continuing with matrix, list, array, dataframe creation.. Check this out…

Create Matrix

matrix_sample= np.matrix(‘8 5 3; 4 7 2; 9 6 1’)

Output

p1

Arithmatic with matrices

matrixsample/6
matrix
sample*2
matrixsample+1
matrix
sample-1

Output

p2

Transpose matrix

import numpy as np
np.transpose(matrix_sample)

Output

p3

Create List

lst = [“India”, 5, 6, 7]

Output

p4

Create array

import numpy as np
np.arange(10)

Output

p5

Create Dataframe

import pandas as pd
dfrme = pd.DataFrame({‘EID’:[3,4,6],‘Gender’:[“M”,“M”,“F”],‘Name’:[“Abi”,“Aki”,“Anu”]})

Output

p6

Create DataSet from existing dataset

from ggplot import mtcars
dst = mtcars
dst_subset = dst[[‘cyl’,‘mpg’]]

Output

p7

I had issues while running command which had ggplot, i fixed it by installing separately and doing some config changes. Better you install latest conda version in which you may not get this issue.